//
// Created by ASUS on 2024/2/28.
//
#include <bits/stdc++.h>
using namespace std;

//元素下标从0开始
class Bcj{
	int n;
	vector<int> fa,rank;
public:
	explicit Bcj(int n):fa(n),rank(n),n(n){
		iota(fa.begin(),fa.end(),0);
		fill(rank.begin(),rank.end(),1);
	}
	~Bcj(){}
	//查找
	int find(int x){
		return fa[x]==x?x:fa[x]= find(fa[x]);
	}
	//合并
	void merge(int i,int j){
		int x=find(i),y=find(j);
		if(x==y) return;
		if(rank[x]<=rank[y]) swap(x,y);
		fa[y]=x;
		rank[x]+=rank[y];
	}
	bool isConnect(int x,int y){
		return find(x)==find(y);
	}
	int kind(){
		int res=0;
		for(int i=0;i<n;i++){
			if(fa[i]==i) res++;
		}
		return res;
	}
};